from django.shortcuts import render, HttpResponse
from cmdb import models
# Create your views here.

user_list = [
    {
        "user": "jack", "pwd": "abc"
    },
    {
        "user": "tom", "pwd": "ABC"
    }
]

def index(request):
    if request.method == "POST":
        username = request.POST.get("username", None)
        password = request.POST.get("password", None)
        temp = {
            "user": username, "pwd": password
        }
        # user_list.append(temp)
        print(username, password)
        # add data to database
        models.UserInfo.objects.create(user=username, pwd=password)
    # read data from database
    user_list = models.UserInfo.objects.all()
    # return HttpResponse("888Hello world!")
    return render(request, "index.html", {"data": user_list})